package com.example.designpatterns.behavioral.iterator;

/**
 * 具体迭代器
 *
 * @author scott
 */
public class ConcreteIterator implements Iterator {

    private Object[] elements;
    private int position = 0;

    public ConcreteIterator(Object[] elements) {
        this.elements = elements;
    }

    @Override
    public boolean hasNext() {
        return position < elements.length;
    }

    @Override
    public Object next() {
        if (hasNext()) {
            Object element = elements[position];
            position++;
            return element;
        }
        return null;
    }

}
